#ifndef QSONGTASTE_H
#define QSONGTASTE_H
#include <vector>
#include <memory>
#include <QtCore/QtCore>
#include <QtGui/QPixmap>
#include <QtNetwork/QtNetwork>


class SongItem
{
public:
	SongItem()
	{
		_isValid = false;
	}
	SongItem(QString const& t, QString const& songId, QString const& songpageUrl)
		:_title(t)
		, _songId(songId)
		, _songPageUrl(songpageUrl)
	{
		_isValid = true;
	}

	void setTitle(QString const& t)
	{
		_title = t;
	}

	QString const& getID()const
	{
		return _songId;
	}

	QString const& getTitle() const
	{
		return _title;
	}
	QString const& getSongPageUrl() const
	{
		return _songPageUrl;
	}
	QString const& getSongExt() const
	{
		return _ext;
	}
	void setSongExt(QString const& ext)
	{
		_ext = ext;
	}
	bool operator==(SongItem const& other) const
	{
		return _songId == other._songId;
	}
	bool operator!=(SongItem const& other) const
	{
		return _songId != other._songId;
	}
	bool isValid()const
	{
		return _isValid;
	}
private:
	QString _songId;
	QString _title;
	QString _ext;
	QString _songPageUrl;
	bool	_isValid;
};

Q_DECLARE_METATYPE(SongItem)
using SongList = std::vector < SongItem  >;



class SongDownload :public QObject
{
	Q_OBJECT
public:
	SongDownload(QObject* parent = 0)
	{
		_valid = false;
	}

	SongItem const& getSongItem()const
	{
		return _si;
	}
	QByteArray const& getData()const
	{
		return _songData;
	}
	bool isValid() const
	{
		return _valid;
	}
Q_SIGNALS:
	void downloadSongFinished();
	void downloadSongProgress(qint64 bytesReceived, qint64 bytesTotal);

private:
	SongItem		_si;
	QByteArray		_songData;
	bool			_valid;
	friend class QSongTaste;
};


class QSongTaste : public QObject
{
	Q_OBJECT

public:

	QSongTaste(QObject * = 0);
	~QSongTaste();


	bool isSignedIn() const;

	SongList getRecommendSongList(int = 1);

	SongList getFavouriteSongList();

	QUrl getSongFileTmpUrl(SongItem const&) const;

	QPixmap const& getUserIcon() const
	{
		return _userImage;
	}

	bool addToFavourite(SongItem const&);
Q_SIGNALS:

	void signInSuccessed(QString const&);

	void downloadSongFinished(SongDownload*);
	void downloadSongProgress(SongDownload*, qint64 bytesReceived, qint64 bytesTotal);


	public Q_SLOTS:
	void signIn(QString const&, QString const&);
	void signOut();


	SongDownload* downloadSong(SongItem const&);

private:
	QPointer<QNetworkAccessManager> _netMgr;

	QString _userID;
	QString _userName;
	QString _userIcon;
	QPixmap _userImage;
	bool	_isSignIn;
};

#endif // QSONGTASTE_H
